package algorithm;

import java.util.HashSet;

public class leetcode_top100_03 {

    public static void main(String[] args) {

        System.out.println(lengthOfLongestSubstring("au"));
    }

    public static int lengthOfLongestSubstring(String s) {

        if (s==null|| "".equals(s)){
            return 0;
        }
        int result=1;
        int num=1;

        char[] chars = s.toCharArray();
        for (int i=0;i<chars.length;i++){
            HashSet<Character> charsSet= new HashSet<>();
            charsSet.add(chars[i]);
            num=1;
            for(int j=i+1;j<chars.length;j++){
                if (charsSet.contains(chars[j])){  //重复了，num重置
                    if (num>result) result=num;
                    break;
                }else{  //没重复
                    charsSet.add(chars[j]);
                    num++;
                    if (num>result) result=num;
                }
            }
        }
        return result;
    }
}
